﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Ozone.Views.Widget
{
    /// <summary>
    /// UCStep.xaml 的交互逻辑
    /// </summary>
    public partial class UCStep : UserControl
    {
        public UCStep()
        {
            InitializeComponent();
        }
        // 定义StepNumber依赖属性
        public static readonly DependencyProperty StepNumberProperty =
            DependencyProperty.Register("StepNumber", typeof(int), typeof(UCStep),
                new PropertyMetadata(10, OnStepNumberChanged));

        public int StepNumber
        {
            get { return (int)GetValue(StepNumberProperty); }
            set { SetValue(StepNumberProperty, value); }
        }

        // 步骤编号变更时的回调方法
        private static void OnStepNumberChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var control = d as UCStep;
            control?.UpdateProgressImage();
        }

        // 更新进度图片的核心方法
        private void UpdateProgressImage()
        {
            if (StepNumber < 0 || StepNumber > 8)
            {
                // 步骤编号超出范围时的处理
                MessageBox.Show("步骤编号应在0-8范围内");
                return;
            }

            try
            {
                // 构建图片路径 - 根据您的资源路径进行调整
                string imagePath = $"/Resources/Images/step/{StepNumber}.png";

                // 创建BitmapImage并设置Source
                BitmapImage bitmap = new BitmapImage();
                bitmap.BeginInit();
                bitmap.UriSource = new Uri(imagePath, UriKind.Relative);
                bitmap.EndInit();

                progressImage.Source = bitmap;
            }
            catch (Exception ex)
            {
                // 图片加载失败时的异常处理
                MessageBox.Show($"加载进度图片失败: {ex.Message}");
            }
        }
        // 可选的：定义图片基础路径属性，增加灵活性
        public static readonly DependencyProperty ImageBasePathProperty =
            DependencyProperty.Register("ImageBasePath", typeof(string), typeof(UCStep),
                new PropertyMetadata("/Resources/Images/step/", OnImageBasePathChanged));

        public string ImageBasePath
        {
            get { return (string)GetValue(ImageBasePathProperty); }
            set { SetValue(ImageBasePathProperty, value); }
        }

        private static void OnImageBasePathChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var control = d as UCStep;
            control?.UpdateProgressImage();
        }
    }
}
